import { Component } from "react";
export default class fn extends Component {
    constructor() {
        super()

        this.state = {
            name: '',
            age: '',
            flag: true,

        }


    }
    change = (e) => {

        this.setState({
            [e.target.name]: e.target.value
        })
    }
    add = () => {
        if (this.state.name === '' || this.state.age === '') {
            alert('不能为空')
        }
        this.setState({
            name: '',
            age: '',

        })
        this.props.add({ name: this.state.name, age: this.state.age, id: +new Date() })
    }
    editOk = () => {
        this.props.editOk({ name: this.state.name, age: this.state.age, id: +new Date() })
    }
    fn = () => {
        console.log(1);
        let name = this.props.msg.name
        let age = this.props.msg.age
        this.setState({
            name,
            age,
        })
    }
    render() {
        let renders = <div><input type='text' name="name" value={this.state.name} onChange={this.change} />
            <input type='text' name="age" value={this.state.age} onChange={this.change} />
        </div>

        if (this.props.flag) {


            this.props.flags()
            this.fn()
        }
        return (

            <div>

                {renders}
                <button onClick={this.editOk}>确定修改</button>  <button onClick={this.add}>提交</button>
            </div>
        )
    }
}